{% extends "mainapp/base.html" %}

{% load static %}
{% load bootstrap %}

{% block title %} 批次产品信息管理 {% endblock %}


{% block content %}


    <div class="row">
        <div class="col-7"><h4 class="text-left">批次产品信息管理</h4></div>
        {% if request.session.role == 'admin' %}
            <div class="col-5 text-right">
                <h5><a href="/mainapp/add_product_base_info/">添加新数据</a>
                    |<a href="/mainapp/product_upload_file/">批量上传</a>
                </h5></div>
        {% endif %}
    </div>

    <div class="row mt-3">
        <div class="col-6">
            <form method="get" action="{% url 'product_batch_info_list' %}">
                <table>
                    <tr>
                        <th><label for="h_lot_number">生产批次号:</label></th>
                        <td><input type="text" id="h_lot_number" class="form-control" name="h_lot_number"
                                   placeholder="输入生产批次号" value="{{ h_lot_number }}"></td>
                        <th><label for="production_lot_number">出货批次号:</label></th>
                        <td><input type="text" id="production_lot_number" class="form-control"
                                   name="production_lot_number"
                                   placeholder="输入出货批次号" value="{{ production_lot_number }}"></td>
                        <td>
                            <button class="btn btn-outline-secondary" type="submit">搜索</button>
                        </td>
                    </tr>
                </table>
            </form>
        </div>
    </div>

    <div class="row mt-4">
        {% if messages %}
            <div class="col-12">
                {% for message in messages %}
                    <div class="alert alert-{{ message.tags }}">{{ message }}</div>
                {% endfor %}
            </div>
        {% endif %}
        <div class="col-12">
            <table class="table table-bordered">
                <thead class="thead-dark">
                <tr>
                    <th>生产批次号</th>
                    <th>产品类型</th>
                    <th>报告编号</th>
                    <th>报告日期</th>
                    <th>客户名称</th>
                    <th>订单号码</th>
                    <th>出货批次号</th>
                    <th>规格型号</th>
                    <th>批量</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {% for product in product_base_info_list %}
                    <tr>
                        <td>{{ product.h_lot_number }}</td>
                        <td>{{ product.h_product_type }}</td>
                        <td>{{ product.report_number }}</td>
                        <td>{{ product.report_date }}</td>
                        <td>{{ product.customer_name }}</td>
                        <td>{{ product.order_number }}</td>
                        <td>{{ product.production_lot_number }}</td>
                        <td>{{ product.specification_model }}</td>
                        <td>{{ product.lot_quantity }}</td>
                        <td>
                            {% if request.session.role == 'admin' %}
                                <a href="{% url 'edit_product_base_info' product.id %}"
                                   class="btn btn-warning btn-sm">修改</a>

                                <form action="{% url 'delete_product_base_info' product.id %}" method="get"
                                      style="display:inline;">
                                    {% csrf_token %}
                                    <button type="submit" class="btn btn-danger btn-sm">删除</button>
                                </form>
                            {% endif %}

                            <a href="{% url 'do_auto_generate_report' product.id %}"
                               class="btn btn-success btn-sm">生成报告</a>
                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>
    </div>
{% endblock %}